package com.ruibang.glass.produce.controller.system;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.produce.domain.req.DeviceReq;
import com.ruibang.glass.produce.entity.Device;
import com.ruibang.glass.produce.service.DeviceService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * @author 宋锦康
 */
@Api(tags = "设备信息接口")
@RestController
@RequestMapping("/api/glass/produce/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取详情", response = ResultBody.class)
    public ResultBody get(@PathVariable String id) {
        return deviceService.getDetail(id);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增实体", response = ResultBody.class)
    public ResultBody add(@RequestBody @ApiParam("实体信息") @Valid Device entity) {
        return deviceService.addDevice(entity);
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改实体", response = ResultBody.class)
    public ResultBody update(@RequestBody @Valid Device entity) {
        return deviceService.modifyDevice(entity);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除实体", response = ResultBody.class)
    public ResultBody delete(@PathVariable @ApiParam("主键ID") String id) {
        return deviceService.deleteById(id);
    }

    @PostMapping("/queryDevicesForPc")
    @ApiOperation(value = "根据条件查询设备信息", response = ResultBody.class)
    public ResultBody queryDevicesForPc(@RequestBody @ApiParam("查询条件") DeviceReq deviceReq) {
        return ResultBody.success(deviceService.queryDevicesForPc(deviceReq));
    }

    @PostMapping("/queryDevices")
    @ApiOperation(value = "根据条件查询设备信息（包含监测点实时数据）", response = ResultBody.class)
    public ResultBody queryDevices(@RequestBody @ApiParam("查询条件") DeviceReq deviceReq) {
        return deviceService.queryDevices(deviceReq);
    }

    @PostMapping("/getUUID")
    @ApiOperation(value = "获取UUID", response = ResultBody.class)
    public ResultBody getUUID() {
        return ResultBody.success(deviceService.getUUID());
    }


    @GetMapping("/getSelectList")
    @ApiOperation(value = "获取所有设备名称和Id集合", response = ResultBody.class)
    public ResultBody getSelectList() {
        return ResultBody.success(deviceService.list(Wrappers.<Device>lambdaQuery().select(Device::getDeviceId, Device::getDeviceName)));
    }

}


